---
title: "Single Column (Scrolling)"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(plotly)
library(covid19italy)
library(ggplot2)
library(dplyr)
italy_total2 <- italy_total %>%
arrange(date) %>%
mutate(diff_hospitalized_with_symptoms = hospitalized_with_symptoms - lag(hospitalized_with_symptoms, default = first(hospitalized_with_symptoms))) %>%
mutate(diff_intensive_care = intensive_care - lag(intensive_care, default = first(intensive_care))) %>%
mutate(diff_total_hospitalized = total_hospitalized - lag(total_hospitalized, default = first(total_hospitalized))) %>%
mutate(diff_home_confinement = home_confinement - lag(home_confinement, default = first(home_confinement))) %>%
mutate(diff_cumulative_positive_cases = cumulative_positive_cases - lag(cumulative_positive_cases, default = first(cumulative_positive_cases))) %>%
mutate(diff_daily_positive_cases = daily_positive_cases - lag(daily_positive_cases, default = first(daily_positive_cases))) %>%
mutate(diff_recovered = recovered - lag(recovered, default = first(recovered))) %>%
mutate(diff_death = death - lag(death, default = first(death))) %>%
mutate(diff_cumulative_cases = cumulative_cases - lag(cumulative_cases, default = first(cumulative_cases))) %>%
mutate(diff_total_test = total_tests - lag(total_tests, default = first(total_tests)))
italy_total2[2:11] <- NULL
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
plot_ly(data = italy_total2,
x = ~ date,
y = ~ log(diff_total_test),
name = 'Daily Tests',
color = '#1f77b4',
type = 'scatter',
mode = '‘lines') %>%
add_trace( y = ~ log(diff_death),
name = "Daily Deaths",
color = '#E41317') %>%
add_trace(y = ~ log(diff_cumulative_positive_cases),
name = 'Daily Positive Cases',
color = 'forestgreen') %>%
layout(title = "Italy - Distribution of Covid19 Cases daily",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of Cases per day on a log scale"),
xaxis = list(title = "Source: Italy Department of Civil Protection"))
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
plot_ly(data = italy_total2,
x = ~ date,
y = ~ diff_cumulative_cases,
name = 'Active',
fillcolor = '#1f77b4',
type = 'scatter',
mode = 'none',
stackgroup = 'one') %>%
add_trace( y = ~ diff_death,
name = "Death",
fillcolor = '#E41317') %>%
add_trace(y = ~ diff_recovered,
name = 'Recovered',
fillcolor = 'forestgreen') %>%
layout(title = "Italy - Distribution of Covid19 Cases",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of Cases"),
xaxis = list(title = "Source: Italy Department of Civil Protection"))
```
### Chart C
```{r}
italy_province %>%
filter(date == max(date), region_name == "Lombardia") %>%
plot_ly(labels = ~province_name, values = ~new_cases,
textinfo="label+percent",
type = 'pie') %>%
layout(title = "Lombardia - New Cases Distribution by Province in Lombardia") %>%
hide_legend()
```
\newpage
Row
-----------------------------------------------------------------------
### New Deaths
```{r}
valueBox(tail(italy_total2$diff_death, n = 1),
icon = "fa-skull")
```
### New Cases
```{r}
valueBox(tail(italy_total2$diff_cumulative_cases, n = 1),
icon = "fa-virus-slash")
```
### New Tests
```{r}
valueBox(tail(italy_total2$diff_total_test, n = 1),
icon = "fa-briefcase-medical")
```
Row
-----------------------------------------------------------------------
### New Deaths
```{r}
gauge(tail(italy_total2$diff_death, n = 1), min = 0, max = max(italy_total2$diff_death), symbol = ' ', gaugeSectors(
success = c(0, 300), warning = c(301, 600), danger = c(601, max(italy_total2$diff_death))
))
```
### New Cases
```{r}
gauge(tail(italy_total2$diff_cumulative_cases, n = 1), min = 0, max = max(italy_total2$diff_cumulative_cases), symbol = ' ', gaugeSectors(
success = c(0, 1000), warning = c(1001, 4000), danger = c(4001, max(italy_total2$diff_cumulative_positive_cases))
))
```
### New Tests
```{r}
gauge(tail(italy_total2$diff_total_test, n = 1), min = 0, max = max(italy_total2$diff_total_test), symbol = ' ', gaugeSectors(
success = c(40001, max(italy_total2$diff_total_test) ), warning = c(20001, 40000), danger = c(0, 20000))
)
```